<template>
    <div class="login-container">
      <!-- 背景图 -->
      <div class="background"></div>
      <!-- 登录框 -->
      <div class="login-box">
        <h2>宠物殡葬用户登录</h2>
        <form @submit.prevent="handleLogin">
          <!-- 用户名输入框 -->
          <div class="input-group">
            <label for="username">用户名</label>
            <input
              type="text"
              id="username"
              v-model="username"
              placeholder="请输入用户名"
              required
            />
          </div>
  
          <!-- 密码输入框 -->
          <div class="input-group">
            <label for="password">密码</label>
            <input
              type="password"
              id="password"
              v-model="password"
              placeholder="请输入密码"
              required
            />
          </div>
  
          <!-- 登录按钮 -->
          <button type="submit" class="login-btn">登录</button>
        </form>
      </div>
  
      <!-- 加载动画 -->
      <div v-if="isLoading" class="loading-overlay">
        <div class="spinner"></div>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        username: "", 
        password: "", 
        isLoading: false, 
      };
    },
    methods: {
      handleLogin() {
        if (!this.username || !this.password) {
          alert("用户名和密码不能为空！");
          return;
        }
        this.isLoading = true;
        setTimeout(() => {
          alert(`登录成功`);
          this.$router.push('/'); 
          this.isLoading = false; 
        }, 1000);
      },
    },
  };
  </script>
  
  <style scoped>
  .login-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("https://img.shetu66.com/2023/07/14/1689302077000124.png"); /* 替换为本地图片路径 */
    background-size: cover;
    background-position: center;
    filter: blur(2px); 
    z-index: -1;
  }
  .login-box {
    background: rgba(255, 255, 255, 0.8); 
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
  }
  .login-box h2 {
    margin-bottom: 20px;
    font-size: 24px;
    color: #333;
  }
  .input-group {
    margin-bottom: 15px;
    text-align: left;
  }
  
  .input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
  }
  
  .input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s ease;
  }
  
  .input-group input:focus {
    border-color: #007bff;
    outline: none;
  }
  .login-btn {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.3s ease;
  }
  .login-btn:hover {
    background-color: #0056b3;
  }
  .loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
  }
  
  .spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid #3498db;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  </style>